home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8030 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: isonews.bbn.hp.com!hpbblb!news
  2. From: Matthias Dittrich <matti>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: (no subject)
  5. Date: 28 Feb 1996 08:17:07 GMT
  6. Organization: Hewlett-Packard Co.
  7. Message-ID: <4h1323$5es@hpbblb.bbn.hp.com>
  8. References: <4gv493$p09@nuacht.iol.ie>
  9. NNTP-Posting-Host: trabant.bbn.hp.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
  14. X-URL: news:4gv493$p09@nuacht.iol.ie
  15.  
  16. Roy Leonard <rleonard@ferrotec.ie> wrote:
  17. >
  18. >Hi all,
  19. >
  20. >I have a strange problem from an embedded system.  I have an array of 
  21. >data, and
  22. >I want to count all the high bits (=1) in the array.
  23. >
  24. >Hopefully there is a way I can do this in C at high speed.  The 
  25. >alternative is assembler, which I would prefer not to do, but I may have 
  26. >to.  Does anyone have any nifty ideas about how I might go about this?
  27. >
  28. >
  29. >The data is of fixed length (roughly 50 long ints).  Each bit is evenly
  30. >weighted.
  31. >Eg.
  32. >
  33. >If the data in binary was "1001001", the total I'm looking for is three.
  34. >
  35. >
  36. If you have a byte array and enough space, it is possible to create
  37. an array of length 256, each field contains the number of high bits
  38. of the corresponding index (i.e. high[0]=0, high[1]=1, high[2]=1,
  39. high[3]=2,...)
  40. The count of all high bits in the array is the sum of high bits of each
  41. byte. I think this is fast.
  42.  
  43. Good luck,
  44. Matthias
  45.  
  46.